<template>
  <div>
    <div class="left-box" v-show="status">
      <router-link :to="{name: 'Home'}">
				<span class="iconfont header-back-icon">&#xe624;</span>
			</router-link>
    </div>
    <div class="top-box" v-show="!status" >
      <div class="header-title" :style="topStyle">
			  <router-link :to="{name: 'Home'}">
				  <span class="iconfont header-title-icon">&#xe624;</span>
			  </router-link>
			  景点详情
		  </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'detailHeader',
  data () {
    return {
      status: true,
      topStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      let scrollTop = document.documentElement.scrollTop
      if (scrollTop >50) {
        this.status = false
        let opacity = scrollTop / 140
        opacity = opacity > 1 ? 1 : opacity
        this.topStyle.opacity = opacity
      } else {
        this.status = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {//上面事件是绑定在全局对象上的，可能会对其他页面造成影响
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style scoped>
  .left-box {
    z-index: 33;
    position: absolute;
    left: .2rem;
    top: .2rem;
    width: .8rem;
    height: .8rem;
    line-height: .8rem;
    border-radius: .4rem;
    text-align: center;
    background: rgba(0, 0, 0, .8);
  }
  .header-title {/*头部标题外部盒子*/
  z-index: 22;
  top: 0;
  left: 0;
  right: 0;
	position: fixed;
	height: .88rem;
	background-color: #00bcd4;
  text-align: center;
	color: #fff;
	line-height: .88rem;
	font-size: .36rem
}
.header-title-icon {/*顶部fixed图标*/
	position: absolute;
	top: 0;
	left:0;
	line-height: .88rem;
	color: #fff;
	width: 1.2rem;
	font-size: .4rem;
	padding-left: .3rem;
}
.header-back-icon {/*左侧图标*/
  color: #fff;
  font-size: .4rem;
}
</style>
